﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace RTS_RPG
{
    public class Block
    {
        public Texture2D image;
        public Vector2 location;
        public Boolean square; //if true this object should use a square reference to check collisions, 
                                //otherwise it should use a circular one

        public Block(Texture2D _image, Vector2 _location, Boolean _square)
        {
            image = _image;
            location = _location;
            square = _square;
        }

        public void draw(SpriteBatch spBatch)
        {
            spBatch.Draw(image, new Vector2(location.X - (image.Width / 2), location.Y - (image.Height / 2)), Color.White);
        }

        public Boolean collision(Vector2 other_location, short half_other_size)
        {
            if (square) // check with square coords
            {
                if (other_location.X + half_other_size >= location.X - (image.Width / 2) &&
                    other_location.X - half_other_size <= location.X + (image.Width / 2) &&
                    other_location.Y + half_other_size >= location.Y - (image.Height / 2) &&
                    other_location.Y - half_other_size <= location.Y + (image.Height / 2))
                    return true;
                return false;
            }
            else        // check with circular coords
            {
                if (Vector2.Distance(other_location, location) <= half_other_size + image.Width / 2)
                    return true;
                return false;
            }
        }
    }
}
